package coreservice

import (
	"strings"
	"unicode"
)

type sort struct {
}

func (p *sort) toSnakeCase(s string) string {
	res := strings.Builder{}
	for i, v := range s {
		if unicode.IsUpper(v) {
			if i != 0 {
				res.WriteRune('_')
			}
			res.WriteRune(unicode.ToLower(v))
		} else {
			res.WriteRune(v)
		}
	}
	return res.String()
}
func (p *sort) GetSort(s string) string {
	var arr = strings.Split(s, " ")
	if len(arr) != 2 {
		return s
	}
	return p.toSnakeCase(arr[0]) + " " + arr[1]
}

var (
	Sort = &sort{}
)
